#include <iostream>

bool IsPrime(int n) {
    bool isPrime = true;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            isPrime = false;
            break;
        }
    }
    return isPrime;
}

int main() {
    std::string inputString;
    std::getline(std::cin, inputString);
    std::string inputWords[3];
    int wordIndex = 0;
    std::string word = "";
    for (char c : inputString) {
        if (c == ' ') {
            inputWords[wordIndex] = word;
            wordIndex++;
            word = "";
        } else {
            word += c;
        }
    }
    inputWords[wordIndex] = word;

    std::string numbers[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};

    if (inputWords[0] == numbers[0] || inputWords[0] == numbers[1] || inputWords[0] == numbers[2] ||
        inputWords[0] == numbers[3] || inputWords[0] == numbers[4] || inputWords[0] == numbers[5] ||
        inputWords[0] == numbers[6] || inputWords[0] == numbers[7] || inputWords[0] == numbers[8] ||
        inputWords[0] == numbers[9]) {
        int number = 0;
        for (int i = 0; i < 10; i++) {
            if (inputWords[0] == numbers[i]) {
                number += i * 100;
                break;
            }
        }
        for (int i = 0; i < 10; i++) {
            if (inputWords[1] == numbers[i]) {
                number += i * 10;
                break;
            }
        }
        for (int i = 0; i < 10; i++) {
            if (inputWords[2] == numbers[i]) {
                number += i;
                break;
            }
        }
        int prime;
        if (IsPrime(number)) {
            prime = number;
        } else {
            for (int i = number - 1; i > 2; i--) {
                if (IsPrime(i)) {
                    prime = i;
                    break;
                }
            }
            for (int i = number + 1; i < 1500; i++) {
                if (IsPrime(i) && (number - prime) > (i - number)) {
                    prime = i;
                    break;
                }
            }
            std::cout << prime << std::endl;
        }
    } else {
        std::cout << "Wrong input" << std::endl;
    }

    return 0;
}

